"""
@name : 2.mail模块
@author : wenyao
@projectname: sanchuanglianxi
"""

#邮件协议
#smtp协议 发邮件协议
#pop3 /imap 收邮件协议

#foxmail

#python收发邮件的模块
#smtplib
#主要用到的是smtplib.SMTP()用于连接SMTP服务器，发送邮件

#授权码  需要在qq邮件浏览器 “账户”选项中获取
#rtcubzcouuqtcaeh
from smtplib import SMTP

# >>> s = SMTP("smtp.qq.com")
# >>> s.login("343292019@qq.com","rtcubzcouuqtcaeh")
# (235, b'Authentication successful')
# >>> tolist = ["fanfan343292019@163.com"]
# >>> msg = """\
# ... From:343292019@qq.com
# ... To:"fanfan343292019@163.com"
# ... Subject:wenyao
# ...
# ... This is a test"""
# >>> s.sendmail("343292019@qq.com",tolist,msg)

#或者这样子连接
# >>> s = SMTP()
# >>> s.connect("smtp.qq.com")
# (220, b'newxmesmtplogicsvrszb5.qq.com XMail Esmtp QQ Mail Server.')
# >>> s.login()

from email.mime.text import MIMEText

#设置第三方smtp服务
mail_host = "smtp.qq.com"
mail_user = "343292019@qq.com"
mail_pass= "rtcubzcouuqtcaeh"

#接收邮箱
rec = "fanfan343292019@163.com"

#构造我们的邮件内容
#正文内容，正文内容类型，正文内容编码
message = MIMEText("wenyao  sendmail test",'plain','utf-8')
message['From'] = mail_user
message['To'] = rec
message['Subject'] = "wenyao"

#发送邮件
s = SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(mail_user,rec,message.as_string())
s.quit()